package com.example.demo.controller;

import com.example.demo.common.R;
import com.example.demo.decorator.Authorize;
import com.example.demo.entity.user.LoginDto;
import com.example.demo.entity.user.LoginVo;
import com.example.demo.entity.user.RegistDto;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/user")
public class UserLoginController {
    @Autowired
    private UserService userService;

    @PostMapping("/regist")
    @Authorize(
            permission = "-",
            label = "用户注册（支持不同登录身份）",
            ifIgnore = true,
            ifIgnoreParamInLog = true
    )
    public R<Boolean> regist(@RequestBody RegistDto dto) throws Exception {
        return userService.regist(dto);
    }

    @PostMapping("/login")
    @Authorize(
            permission = "-",
            label = "用户登录（支持不同登录身份）",
            ifIgnore = true,
            ifIgnoreParamInLog = true
    )
    public R<LoginVo> login(@RequestBody LoginDto dto, HttpServletRequest request) throws Exception {
        // RequestPojo iifr = RequestUtils.getIpInfoFromRequest(request);
        return userService.login(dto);
    }
}
